using System;
using System.Collections.Generic;
using NUnit.Framework;
using RMH.DataAccess;
using RMH.Entities;
using RMH.UnitTests;

namespace RMH.IntegrationTests.Repository
{
    [TestFixture]
    public class StayRepository_when_getting_current_stays : TransactionalRepositoryBase<StayRepository>
    {
        private Stay currentStay = new Stay
                                       {
                                           CheckinDate = DateTime.Now.AddDays(-1),
                                           CheckoutDate = DateTime.Now.AddDays(1)
                                       };

        private Stay currentStay2 = new Stay   {  // checkout date is null
                                                   CheckinDate = DateTime.Now.AddDays(-1) 
                                               };

        private Stay previousStay = new Stay {
                                                 CheckinDate = DateTime.Now.AddDays(-4),
                                                 CheckoutDate = DateTime.Now.AddDays(-2)
                                             };
        private Stay futureStay = new Stay
                                      {
                                          CheckinDate = DateTime.Now.AddDays(6),
                                          CheckoutDate = DateTime.Now.AddDays(8)
                                      };

        private IList<Stay> returnedStays;


        public override void establish_context()
        {
            base.establish_context();
            repository.Save(currentStay);
            repository.Save(currentStay2);
            repository.Save(futureStay);
            repository.Save(previousStay);
        }


        public override void because()
        {
            returnedStays = repository.GetCurrentStays();
        }

        [Test]
        public void only_returns_stays_that_overlap_the_current_date()
        {
            returnedStays.ShouldContain(currentStay);
            returnedStays.ShouldContain(currentStay2);
            returnedStays.ShouldNotContain(previousStay);
            returnedStays.ShouldNotContain(futureStay);
        }
    }
}